<template>
  <div class="box">
    <van-nav-bar
      title="订单页"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-list
      disabled-text="以下地址超出配送范围"
      :list="list1"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
    <div>
      <p><van-contact-card type="add" add-text="添加地址" @click="onAdd" /></p>
      <p><van-empty image="error" description="暂无订单" /></p>
      <p>
        <van-submit-bar :price="0" button-text="提交订单" @submit="onSubmit" />
      </p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { setmordiz } from "../../service/user";
// import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { ref, reactive, onMounted, computed } from "vue";
import { useCounterStore } from "@/stores/counter";
let router = useRouter();
// const store = useStore();
let store=useCounterStore();
let list = ref<any>([]);
let list1 = reactive<any>({});
const list2 = [
  {
    id: "1",
    name: "张三",
    tel: "13000000000",
    address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
    isDefault: true,
  },
];
onMounted(() => {
  setmordiz({ userid: store.userid }).then((res) => {
    if (res.data.code === "200") {
      list.value = res.data.data;
      console.log(list.value);
    }
  });
});
list1 = computed(() => {
  return list.value.map((item:any) => {
    return {
      id: item.addressid,
      name: item.name,
      tel: item.tel,
      address: item.province + item.city + item.county + item.addressDetail,
      isDefault: item.isDefault,
    };
  });
});
function onClickLeft() {
  history.back();
}
function onSubmit() {}
function onAdd() {
  router.push("/address");
}
function onEdit() {}
</script>

<style lang="scss" scoped>
.box {
  background-color: #f5f5f5;
  height: 100vh;
}
</style>
